package com.zretc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.zretc.entity.Users;

@Controller
@SessionAttributes("ulogin") // 比较好的做法是在model范围内有一个ulogin的对象
//// 需要将用户登录的信息存储起来，存储到session中
public class LoginController {

	@PostMapping("login")
	public String login(@ModelAttribute("ulogin") Users user) {
		if ("admin".equals(user.getUsername()) && "123456".equals(user.getUserpwd())) {
			return "manage";
		}
		return "login";
	}

	@ModelAttribute("ulogin")
	public Users getUsers() {
		return new Users();
	}
	
	@GetMapping("login")
	public String loginIndex() {
		return "login";
	}

}
